<style lang="scss" scoped>
@import "../../css/list.scss";
header {
  .seek_box {
    height: 0.45rem;
    .left,
    .right {
      padding: 0 0.15rem;
      line-height: 0.45rem;
    }
    .center {
      padding: 0.08rem 0;
      border-radius: 0.05rem;
    }
    .seek {
      border-radius: 0.05rem;
    }
  }
}
nav {
  li {
    height: 0.45rem;
  }
}
.empty {
  height: 3rem;
}
</style>

<template>
  <div class="seek_end">
    <header class="padding-l15">
      <ul class="seek_box flex-col box-sizing">
        <!-- <li class="left text-c">
                    <span>成都</span>
                    <i class="iconfont icon-shouji"></i>
                </li> -->
        <li class="box-sizing box1 center">
          <div class="seek flex-col full bgfff">
            <div class="padding-lr5 box-center">
              <i class="iconfont icon-sousuo font-20"></i>
            </div>
            <div class="box1">
              <input class="full" v-model="seekText" type="text" :placeholder="titText">
            </div>
            <div class="padding-lr10 box-center" v-show="seekText.length" @click="seekText = ''">
              <i class="iconfont icon-qingchu"></i>
            </div>
          </div>
        </li>
        <li class="right box-center" @click="getList">
          搜索
        </li>
      </ul>
    </header>
    <nav>
      <ul class="flex-col bgfff border-b">
        <li class="box-center box1">区域</li>
        <li class="box-center box1">均价</li>
        <li class="box-center box1">推荐</li>
        <li class="box-center box1">建筑面积</li>
      </ul>
    </nav>
    <main>
      <ul class="index_list padding-lr15 bgfff">
        <li class="flex-col border-b" v-for="(it,i) in houseList" data-id="housesCode" :key="i" @click="toRouter('houses_info/'+it.housesCode)">
          <div class="it_bg img-bg" :style="{backgroundImage:`url(${it.housesImgurl})`}"></div>
          <div class="it_info box1">
            <div class="padding-b10">{{it.housesName}}</div>
            <div class="font-12 c82 padding-b5 ">轻呼吸 · 慢生活 ·泉世界</div>
            <div class="font-12 c82 padding-b10 box-space">{{it.housesAddress}}
              <span class="cred">1.6km</span>
            </div>
            <div class="btn cred">
              <i class="iconfont icon-dianhua1"></i>
              <a :href="'tel:'+it.housesPhone" class="cred text-none">{{it.housesPhone}}</a>
            </div>
          </div>
        </li>
        <li class="empty box-center c82">暂无数据</li>
      </ul>
    </main>
  </div>
</template>

<script>
export default {
  name: "seek_end",
  data() {
    return {
      houseHistory: true, // 默认楼盘
      seekText: "",
      houseList: [],
      titText: "请输入关键字找楼盘"
    };
  },
  mounted() {
    let that = this;
    this.$nextTick(() => {
      that.seekText = that.$route.params.text;
      that.getList();
    });
  },
  methods: {
    getList(has = false) {
      if (!this.seekText.length) return;
      let that = this;
      let housesName = this.seekText;

      let page = this.hasPage(has); //需要分页
      if (!has) page = that.page = 1; //搜索
      if (!page) return;

      let ops = {
        page,
        limit: that.limit,
        housesName
      };

      if (that.$route.params.id) {
        delete ops["housesName"];
        ops["clientName"] = this.seekText;
      } else {
        ops["lng"] = that.getCache("point").lng || null;
        ops["lat"] = that.getCache("point").lat || null;
      }

      let url = that.$route.params.id ? "client/list" : "houses/list";

      this.http.get(url, ops).then(res => {
        that.totalPage = res.totalPage;
        if (has) {
          that.houseList.push(res.data.list);
        } else {
          that.houseList = res.data.list;
        }
      });
    }
  }
};
</script>


